//
//  LoanTabBarController.m
//  Loan
//
//  Created by hejinhui on 2017/11/7.
//  Copyright © 2017年 hejinhui. All rights reserved.
//

#import "LoanTabBarController.h"
#import "HomeViewController.h"
#import "MessageViewController.h"
#import "PersonalCenterController.h"
#import "MoneyViewController.h"
#import "LoanNavgaionController.h"
@interface LoanTabBarController ()

@end

@implementation LoanTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    HomeViewController *home = [[HomeViewController alloc]init];
    MoneyViewController *money = [[MoneyViewController alloc]init];
    MessageViewController *mssageVc = [[MessageViewController alloc]init];
    PersonalCenterController *personVc = [[PersonalCenterController alloc]init];
    
    [self addChildVc:home title:@"首页" image:@"home" selectedImage:@"home_s"];
    [self addChildVc:money title:@"理财" image:@"money" selectedImage:@"money_s"];
    [self addChildVc:mssageVc title:@"消息" image:@"message" selectedImage:@"message_s"];
    [self addChildVc:personVc title:@"我的" image:@"personal" selectedImage:@"personal_s"];
}

/**
 *  添加一个子控制器
 *
 *  @param childVc       子控制器
 *  @param title         标题
 *  @param image         图片
 *  @param selectedImage 选中的图片
 */
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置子控制器的文字
    childVc.title = title; // 同时设置tabbar和navigationBar的文字
    
    // 设置子控制器的图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor blueColor];
    
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    self.tabBar.tintColor = [UIColor whiteColor];
    
    // 先给外面传进来的小控制器 包装 一个导航控制器
    LoanNavgaionController *nav = [[LoanNavgaionController alloc] initWithRootViewController:childVc];
    // 添加为子控制器
    [self addChildViewController:nav];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
